<template>
	<view>
		<view class="addresslist" v-for="item in addressLists">
			<view class="des">
				<view>{{item.name}} {{item.gander}} {{item.mobile}}</view>
				<view>{{item.address}}</view>
			</view>
			<view class="icon">
				<u-icon name="edit-pen" size="30" @click="updateAddress(item._id)"></u-icon>	
			</view>
		</view>
		<view class="add">
			<u-button type="error" shape="circle" @click="addAddress()">新增地址</u-button>
		</view>
	</view>
</template>

<script>

	const CloudAddress=uniCloud.importObject("address")
	export default {
		data() {
			return {
				user_id:"",
				addressLists:[],
			};
		},
		onLoad() {
			this.user_id = uni.getStorageSync("uni-id-pages-userInfo")._id;
		},
		onShow() {
			this.getAddress(this.user_id);
		},
		methods:{
			addAddress(){
				uni.navigateTo({
					url:`/pages/address/addAddress/addAddress`
				})
			},
			updateAddress(address_id){
				uni.navigateTo({
					url:`/pages/address/updateAddress/updateAddress?&address_id=${address_id}`
				})
			},
			getAddress(user_id){
				CloudAddress.getAddress(user_id).then(res=>{
					console.log(res);
					this.addressLists=res.data;
				})
			},
			
		}
	}
</script>

<style lang="scss">
.addresslist{
	width: 95%;
	height: 100rpx;
	box-sizing: content-box;
	padding: 20rpx;
	display: flex;
	justify-content: space-between;
	border-bottom: 1rpx solid red ;
	.des{
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}
}

.add{
	width: 100%;
	position: fixed; 
	bottom: var(--window-bottom,0);
	box-sizing: content-box;
}
</style>
